#include "CMainUIManage.h"
#include <QDebug>

#include "MainStatus/UIMainStatusAll.h"
#include "MainStatus/UIMainStatusMod.h"


CMainUIManage::CMainUIManage()
{
    m_CurrentMainUI.reset();
    m_mapMainStatus.clear();
    m_lastModel = emModRunNone;

    m_statusAll.reset();
    m_statusMod.reset();

    qDebug() << "CMainUIManage 单例构造";
}

CMainUIManage::~CMainUIManage()
{
    m_mapMainStatus.clear();

    qDebug() << "CMainUIManage 单例析构";
}

//初始化信息;
void CMainUIManage::InitData(IUIElement* pElement)
{
    m_statusAll = std::make_shared<UIMainStatusAll>(pElement);
    m_statusMod = std::make_shared<UIMainStatusMod>(pElement);
    SetMainStatus(m_statusAll->GetMainStatus(), m_statusAll);
    SetMainStatus(m_statusMod->GetMainStatus(), m_statusMod);
    DisplayMain(m_statusAll->GetMainStatus());
}

//显示对应的主界面;
void CMainUIManage::DisplayMain(EnumMainStatus emStatus)
{
    std::shared_ptr<IUIMainStatus> status = GetMainStatus(emStatus);
    SetCurrentMainStatus(status);
}

//获取StatusInfo;
std::shared_ptr<IUIMainStatus> CMainUIManage::GetMainStatus(EnumMainStatus emStatus)
{
    return m_mapMainStatus[emStatus];
}

//设置StatusInfo;
void CMainUIManage::SetMainStatus(EnumMainStatus emStatus, std::shared_ptr<IUIMainStatus> status)
{
    m_mapMainStatus[emStatus] = status;
}

//获取currentStatus;
std::shared_ptr<IUIMainStatus> CMainUIManage::GetCurrentMainStatus()
{
    return m_CurrentMainUI;
}

//设置currentStatus;
void CMainUIManage::SetCurrentMainStatus(EnumMainStatus status)
{
    std::shared_ptr<IUIMainStatus> pStatus = GetMainStatus(status);
    if (!pStatus)
    {
        return;
    }

    if (m_CurrentMainUI)
    {
        if (m_CurrentMainUI->GetMainStatus() == status)
        {
            return;
        }
    }

    SetCurrentMainStatus(pStatus);
}

//设置currentStatus;
void CMainUIManage::SetCurrentMainStatus(std::shared_ptr<IUIMainStatus> status)
{
    if (m_CurrentMainUI)
    {
        if (!status)
        {
            qDebug() << "CMainUIManage::SetCurrentMainStatus 状态异常";
            return;
        }
        if (m_CurrentMainUI->GetMainStatus() == status->GetMainStatus())
        {
            return;
        }

        m_CurrentMainUI->AfterDisplay();
    }
    
    status->PreDisplay();
    status->Display();
    m_CurrentMainUI = status;
}

//设置最后点击的设计模式;
void CMainUIManage::SetLastModel(EnumModRun emModel)
{
    m_lastModel = emModel;
    return;
}

//获取最后点击的设计模式;
EnumModRun CMainUIManage::GetLastModel()
{
    return m_lastModel;
}